package router

import (
	"github.com/AiGenApps/goout-server/handlers"
	"github.com/AiGenApps/goout-server/middleware"
	"github.com/gin-gonic/gin"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()

	// 添加全局中间件
	r.Use(middleware.Cors())

	// 基础健康检查
	r.GET("/ping", func(c *gin.Context) {
		c.JSON(200, gin.H{"message": "pong"})
	})

	// 版本信息接口
	r.GET("/version", handlers.GetVersion)

	// 添加数据库测试路由
	r.GET("/test/db", handlers.TestDB)

	// 用户相关路由
	userHandler := handlers.NewUserHandler()
	r.POST("/users/register", userHandler.Register)
	r.POST("/users/login", userHandler.Login)

	// 需要认证的路由
	auth := r.Group("/")
	auth.Use(middleware.Auth())
	{
		auth.GET("/users/me", userHandler.GetCurrentUser)
		auth.GET("/users/validate", userHandler.ValidateToken)
		auth.PUT("/users/profile", userHandler.UpdateProfile)
	}

	return r
}
